| # Text | Other Swing Changes

> ## Default HTML Font Is Now Serif

> HTML text -- including HTML text used in labels, buttons, and so on -- used to be in SansSerif font by default. As of v 1.3, the default font is Serif.

> ## HTMLEditorKit insertAtBoundry => insertAtBoundary

> A method in HTMLEditorKit.InsertHTMLTextAction, insertAtBoundry, was misspelled. It's been deprecated and insertAtBoundary has been added.

> ## Automatic Handling of DocumentEvents

> The default functionality of managing the DocumentEvent has been moved (from CompositeView) and raised from package private to public. Subclassing has been made much easier as the management of the DocumentEvent is now distributed to the protected methods:

> `
> - updateChildren
> - forwardUpdate
> - forwardUpdateToView
> - updateLayout
> `

> To accomplish its behavior, the methods managing the children of the view also needed to be moved from CompositeView to View.

> `
> - removeAll
> - remove
> - append
> - replace
> `

> The following methods were added to the javax.swing.text.View: ``

> - protected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f)
> - protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory f)
> - protected void forwardUpdateToView(View v, DocumentEvent e, Shape a, ViewFactory f)
> - protected void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a)
> - public void removeAll()
> - public void remove(int i)
> - public void insert(int offs, View v)
> - public void append(View v)
> - public void replace(int offset, int length, View[] views)

> ## BoxView: Add axis property, layoutChanged Method

> BoxView has an axis argument which subclasses previously could not get at. A subclass that sets it's axis based upon i18n considerations needs this as a property. The layout of the box should also be treated seperate from the requested size as in some cases (such as a table) the layout may become invalid independant of the children's preferences.

> The following methods have been added to javax.swing.text.BoxView:

> `
> - public int getAxis()
> - public void setAxis(int axis)
> - public void layoutChanged(int axis)
> `

> ## ParagraphView now extends FlowView

> The View protocol supports building flows, but the only previous implementation had been ParagraphView which creates relatively simple paragraph flows. The functionality can be generalized substantially to do things like shaped flows, page breaking, etc. Generalizing the functionality will make the creation of alternative flows much easier.

> A new class called FlowView takes a strategy to translate the logical structure to a physical structure. The strategy is defined by a nested static class called FlowStrategy. ParagraphView extends FlowView adding just that behavior which is paragraph-specific (i.e line spacing, first line indent, alignment, etc). This change adds the following method to the javax.swing.text.View class:

> `
> - public int getViewIndex(int pos, Position.Bias b)
> `

> ## FormView Localization; SUBMIT, RESET deprecated

> Class `javax.swing.text.html.FormView` was not previously localizable. There are two public static final Strings, SUBMIT and RESET, that are used to determine the text for <form> elements in an HTML document. As they are public static final they can not be localized. SUBMIT and RESET have been deprecated, the values are now obtained from the UIManager properties: `FormView.submitButtonText` and `FormView.resetButtonText`.

> ## Serialization

> Here's a summary of the serialization related changes in the swing.text package:
> - `javax.swing.text.html.parser.ParserDelegator` now implements Serializable.
> - Added a nullary constructor to the public static innner class `HTML.Tag` to allow serialization of subclasses to work.

> ## HTML Package: Expose More of AbstractWriter

> AbstractWriter is used as a base class for developers wishing to provide custom writing out of a text Document. For example, HTMLWriter extends AbstractWriter, and is used in the html package to output html. The problem with AbstractWriter was that most of the methods and ivars it provided were private. Subclasses had to resort to copying numerous methods and ivars to be useful. HTMLWriter extends AbstractWriter, but ended up copying all the ivars, and overriding almost all the methods. The following changes open up the API in AbstractWriter, making it more useful by itself. This makes HTMLWriter much simpler, and it won't have to copy as much from AbstractWriter.

> See:

> `
> - public int getStartOffset()
> - public int getEndOffset()
> - protected Writer getWriter()
> - protected int getLineLength()
> - protected void setCurrentLineLength(int length)
> - protected int getCurrentLineLength()
> - protected boolean isLineEmpty()
> - protected void setCanWrapLines(boolean newValue)
> - protected boolean getCanWrapLines()
> - public void setLineSeparator(String value)
> - public String getLineSeparator()
> - protected int getIndentLevel()
> - protected void writeLineSeparator() throws IOException
> - protected void write(char[] chars, int startIndex, int length) throws IOException
> - protected void output(char[] content, int start, int length) throws IOException
> `

> ## HTML Package: Expose More CSS1 Support

> The html package supports CSS 1. One of the abilities of CSS is to support cascading of style sheets (as the name implies), that is more than one style sheet can influence the presentation simultaneously. For example a browser usually has a style sheet that defines the default styles, a particular page might also have a style sheet that overrides those provided by the browser. The following methods expose this to developers, allowing them to link style sheets:

> `
> - public synchronized void addStyleSheet(StyleSheet ss)
> - public synchronized void removeStyleSheet(StyleSheet ss)
> - public StyleSheet[] getStyleSheets()
> `

> ## Simplify HTML Insertions

> Previously it was not very easy for developers to insert arbitrary html into an existing html document. To accomplish this, the developer needed to have an intimate knowledge of the swing text package, as well as the html package. Many developers have used dynamic html, which provides a handful of methods that make it trivial to insert html into an existing page. To accomodate these users we now expose methods that closely mirror those provided by dynamic html:
> `
> - public void setInnerHTML(Element elem, String htmlText) throws BadLocationException, IOException
> - public void setOuterHTML(Element elem, String htmlText) throws BadLocationException, IOException
> - public void insertAfterStart(Element elem, String htmlText) throws BadLocationException, IOException
> - public void insertBeforeEnd(Element elem, String htmlText) throws BadLocationException, IOException
> - public void insertBeforeStart(Element elem, String htmlText) throws BadLocationException, IOException
> - public void insertAfterEnd(Element elem, String htmlText) throws BadLocationException, IOException
> - public Element getElement(String id)
> - public Element getElement(Element e, Object attribute, Object value)
> `

> And this is constant has been added to class HTMLEditorKit.ParserCallback:

> `
> - public static final Object IMPLIED
> `

> ## New text Package ZoneView class

> Problem:
> The swing text package uses View objects to represent a presentation of the document model for the sake of layout and rendering. If the model is large, the number of view objects that get created is large, in spite of only being able to view a small number of them. A View implementation is needed that defers creation of the objects until they are actually needed for display. This can be done by building zones with an estimated size that get replaced with the actual View objects when they are needed. This can substantially reduce the amount of memory used for large documents.

> Solution:
> The following class called ZoneView supports zones that don't consume much memory until actively viewed or edited. WrappedPlainView which will become more heavyweight with its support of bidi for i18n will benefit substantially from this class by changing it's superclass from BoxView to ZoneView (which is a BoxView).

> See:

> `
> - javax.swing.text.ZoneView
> `

> ## New text Package AsyncBoxView class

> Problem:
> The swing text package uses View objects to represent a view of the document model to handle layout and rendering. Layout is done on the event handling thread like most other things. Layout is sometimes quite expensive in terms of cpu time, and causes the user interface to freeze while performing layout. The text package has some support of concurrency however, so this should be extended to include performing layout asynchronous to the gui event handling thread. A View implementation is needed that performs layout asynchronously.

> Solution:
> To address this need, the following classes are being added to the text package. For more information visit The Swing Connection.

> `
> - javax.swing.text.AsyncBoxView
> - javax.swing.text.LayoutQueue
> `

> ## Add getGraphics Method to text View Class

> A method is included on the javax.swing.text.View class to fetch the Graphics object that will be used to render.

> See:

> `
> - public Graphics getGraphics()
> `

Copyright © 1999 Sun Microsystems, Inc. All Rights Reserved. Please send comments to: swing-feedback@java.sun.com. This is not a subscription list. | Java Software